<template>
  <div class="app-container">
    <el-card shadow="never" v-loading="loading">
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane v-for="item in roleList" :key="item.uid" :label="item.roleName" :name="item.roleName"></el-tab-pane>
      </el-tabs>
      <el-row :gutter="5">
        <el-col :span="24" class="main-card-view">
          <el-row>
            <el-card shadow="never" class="top-search-view-card">
              <el-row>
                <el-form :inline="true" :model="searchForm" class="demo-form-inline search-view">
                  <el-form-item label="用户名">
                    <el-input v-model="searchForm.userName" placeholder="请输入用户名"></el-input>
                  </el-form-item>
                  <el-form-item>
                    <el-button type="primary" @click="handleSearch" class="search-button">查询</el-button>
                  </el-form-item>
                </el-form>
              </el-row>
            </el-card>
          </el-row>
          <el-row>
            <el-card shadow="never">
              <el-table :data="tableData" :stripe="true" style="width: 100%">
                <el-table-column prop="userName" align="center" label="用户名" />
                <el-table-column prop="logName" align="center" label="登录账户" />
                <el-table-column prop="roleName" align="center" label="角色" />
                <el-table-column prop="telephone" align="center" label="联系电话" />
                <el-table-column prop="contactAddress" align="center" label="联系地址" />
                <el-table-column prop="createTime" align="center" label="添加时间" />
                <el-table-column align="center" label="操作" width="200">
                  <template slot-scope="scope">
                    <el-button type="text" @click="getName(scope.row)">选择</el-button>
                  </template>
                </el-table-column>
              </el-table>
              <XPagination ref="pageInfo" :total="total" :get-data="getList" />
            </el-card>
          </el-row>
        </el-col>
      </el-row>
    </el-card>
  </div>
</template>

<script>
import XPagination from "./xpagination/XPagination";
import * as userInfo from "../api/userInfo"
import * as sysRole from "../api/sysRole";
export default {
  name: "list",
  components: { XPagination },
  data () {
    return {
      searchForm: {
        userName: "",
        region: ""
      },
      tableData: [],
      loading: false,
      dialogVisible: false,
      total: 0,
      dialogTitle: "新增账户",
      form: {
        uid: "",
        userName: "",
        telephone: "",
        contactAddress: "",
        notes: "",
        roleUid: "",
        roleName: "",
        region: "",
        logName: "",
        pwd: "",
      },
      editStatus: "add",
      formRules: {
        userName: [
          { required: true, message: '不能为空', trigger: 'blur' },
        ],
        telephone: [
          { required: true, message: '不能为空', trigger: 'blur' },
        ],
        contactAddress: [
          { required: true, message: '不能为空', trigger: 'blur' },
        ],
        notes: [
          { required: true, message: '不能为空', trigger: 'blur' },
        ],
        roleUid: [
          { required: true, message: '不能为空', trigger: 'blur' },
        ],
        region: [
          { required: true, message: '不能为空', trigger: 'blur' },
        ],
        logName: [
          { required: true, message: '不能为空', trigger: 'blur' },
        ],
        pwd: [
          { required: true, message: '不能为空', trigger: 'blur' },
        ],
      },
      roleList: [],
      activeName: '管理员'
    }
  },
  methods: {
    getList (pageInfo) {
      const param = {
        ...this.searchForm,
        ...pageInfo,
        roleName: this.activeName
      }
      userInfo.queryByPage(param).then(response => {
        console.log(response)
        this.tableData = response.data.data.rows
        this.total = response.data.data.total
        this.loading = false
      }).catch(error => {
        console.log(error)
      })
    },
    handleSearch () {
      this.$refs.pageInfo.loadData()
    },
    getRoleList () {
      const param = {}
    //   sysRole.queryByPage(param).then(response => {
    //     console.log(response)
    //     this.roleList = response.data.data.rows
    //   }).catch(error => {
    //     console.log(error)
    //   })
    },
    getName (row) {
      this.$emit('getName', row)
    },
    handleClick () {
      this.handleSearch()
    }
  },
  mounted () {
    this.getRoleList()
    this.handleSearch()
  }
}
</script>

<style scoped lang="scss"></style>
